import { Body, Controller, Get, Post, Query } from "@nestjs/common";
import { CreateLog, Roles } from "@/common/decorators";
import { Role } from "@/common/enum/role.enum";
import { RequiredPipe } from "@/common/pipes/required.pipe";
import { SysDictType } from "@/database/entity/SysDictType";
import { DictTypeService } from "./dict-type.service";
import { CreateDictTypeDto } from "./dto/create-dict-type.dto";
import { PageDictTypeDto } from "./dto/page-dict-type.dto";
import { UpdateDictTypeDto } from "./dto/update-dict-type.dto";

@Controller("sys/dictType")
export class DictTypeController {
    constructor(private readonly dictService: DictTypeService) {}

    /** 新增数据字典 */
    @CreateLog({ module: "系统字典", type: "create", action: "创建数据字典" }, SysDictType)
    @Roles(Role.SUPER_ADMIN)
    @Post("create")
    async create(@Body() data: CreateDictTypeDto) {
        return this.dictService.create(data);
    }

    /** 删除数据字典 */
    @CreateLog({ module: "系统字典", type: "delete", action: "删除数据字典" }, SysDictType)
    @Roles(Role.SUPER_ADMIN)
    @Post("remove")
    async remove(@Body("id", RequiredPipe) id: string) {
        return this.dictService.remove(id);
    }

    /** 更新数据字典 */
    @CreateLog({ module: "系统字典", type: "update", action: "更新数据字典" }, SysDictType)
    @Roles(Role.SUPER_ADMIN)
    @Post("update")
    async update(@Body() data: UpdateDictTypeDto) {
        return this.dictService.update(data);
    }

    /** 查询单个记录 */
    @Get("findById")
    async findById(@Query("id", RequiredPipe) id: string) {
        return this.dictService.findById(id);
    }

    /** 获取数据字典分页列表 */
    @Post("page")
    async page(@Body() data: PageDictTypeDto) {
        return this.dictService.page(data);
    }
}
